/*
公共函数库
黄
2016.9.10
*/
!function(){
	function H(){
	}
	H.prototype.ajaxurl = function(url,title){
		//生成随机数
		var num = new Date().getTime()+this.randome(5);
		//dom的id
		var dom_id = 'ajaxModal_H'+num;
		//生成元素
		$('body').append($('<div style="display:none" id="'+dom_id+'"></div>'));
		$('#'+dom_id).load(url,function(){								  
			layer.open({
				type: 1,
				title:title,
				shadeClose: false,
				shade: 0.8,
				shift:0,
				area: ['auto', 'auto'],
				btn: ['确定', '取消'],
				content: $('#'+dom_id), //dom
				yes: function(index, layero){	
					call_submit(index);
				},
				end:function(){
					$('#'+dom_id).remove();
				}
			});									  									  
		});
	}
	H.prototype.ajaxiframe = function(href,w,h,title='',full=0){
		//生成元素
		var that = this;
		//看是否全屏
		full = 1 == full?full:0;
		//获取宽度高度
		w = full?'100%':w?w+'px':'auto';
		h = full?'100%':h?h+'px':'auto';
		var index = layer.open({
				type: 2,
				title:title,
				shadeClose:false,
				shade: 0.8,
				shift:2,
				area: [w, h],
				btn: ['确定', '取消'],
				content: href, //dom
				yes: function(index, layero){
    				var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
    				iframeWin.call_submit(index);
				},
				end:function(){
					$('#ajaxiframechilddate_'+index).remove();
				}
		});
	}
	H.prototype.randome = function(m){
		m = m > 13 ? 13 : m;
		var num = new Date().getTime();
		return num.toString().substring(13 - m);
	}
	H.prototype.ajax = function(url, data, type, callback){
		$.ajax({
			url: url,
			data: data,
			type: type,
			success: function(data){
				if (data.errno > 0) {
					layer.msg(data.errmsg,{icon:2,time: 3000});
				} else {
					callback(data);
				}
			},
		})
	}
	H.prototype.times = function(unix){
		let tm = new Date(unix*1000);
		let yy = tm.getFullYear();
		let mm = tm.getMonth()<9?'0'+(tm.getMonth()+1):tm.getMonth()+1;
		let dd = tm.getDate()<10?'0'+tm.getDate():tm.getDate();
		let hh = tm.getHours()<10?'0'+tm.getHours():tm.getHours();
		let ii = tm.getMinutes()<10?'0'+tm.getMinutes():tm.getMinutes();
		let ss = tm.getSeconds()<10?'0'+tm.getSeconds():tm.getSeconds();
		return yy+'-'+mm+'-'+dd+' '+hh+':'+ii+':'+ss;
	}
	window.H = new H();
}()